<template>
    <div class="home-page">
        <section class="top-section">
            <div class="card">
                <div class="card-item">
                    <div class="card-item__content">
                        <div>
                            <h2>Hi, I'm Innei</h2>
                            <h3>捕捉人生中的每一份精彩时刻与温暖</h3>
                            <h4>一位正在学习前端的程序员小白</h4>
                            <br>
                            <button class="more">了解更多</button>
                        </div>

                        <div style="height: 60px;  width: 100%;line-height: 60px;">
                            <div>
                                <span>文章（100）</span>
                                <span> 图片（300） </span>
                                <span>分类（10）</span>
                                <span> 访客量（8000） </span>
                            </div>
                        </div>
                    </div>
                    <div class="card-item__img">
                        <img src="https://picsum.photos/400/400" alt="" />
                    </div>
                </div>
            </div>

            <div class="arrow">
                <img src="@/assets/svg/arrow-down.svg" alt="">
            </div>
        </section>
        <section class="posts-section">
            <div class="title">
                <h2>近期博文</h2>
                <p>分享技术积累与人生感悟</p>
            </div>
            <div class="container">
                <div class="content left" @click="router.push('/essay-detail')">
                    <img src="https://picsum.photos/300/400" alt="" />
                    <div class="detail">
                        <h3>排查了一个导致页面白屏的问题</h3>
                        <p>我在公司维护的 Felo Search 项目近期收到了大量投诉，部分页面会出现白屏现象。我负责去重点排查，有位同事用自己的手机测试后，发现在 iOS 16 系统下会稳定出现，这大概率就是
                            JS 执行出错导致了。我的分析过程大致如下我在公司维护的 Felo Search 项目近期收到了大量投诉，部分页面会出现白屏现象</p>
                    </div>
                </div>
                <div class="content right" @click="router.push('/essay-detail')">
                    <div class="item">
                        <div class="item-img">
                            <img src="https://picsum.photos/200/200" alt="" />
                        </div>
                        <div class="item-content">
                            <h3>排查了一个导致页面白屏的问题</h3>
                            <p> 我在公司维护的 Felo Search 项目近期收到了大量投诉，部分页面会出现白屏现象。我负责去重点排查，有位同事用自己的手机测试后</p>

                        </div>

                    </div>
                    <div class="item">
                        <div class="item-img">
                            <img src="https://picsum.photos/200/200" alt="" />
                        </div>
                        <div class="item-content">
                            <h3>排查了一个导致页面白屏的问题</h3>
                            <p> 我在公司维护的 Felo Search 项目近期收到了大量投诉，部分页面会出现白屏现象。我负责去重点排查，有位同事用自己的手机测试后</p>
                        </div>

                    </div>
                    <div class="item">
                        <div class="item-img">
                            <img src="https://picsum.photos/200/200" alt="" />
                        </div>
                        <div class="item-content">
                            <h3>排查了一个导致页面白屏的问题</h3>
                            <p> 我在公司维护的 Felo Search 项目近期收到了大量投诉，部分页面会出现白屏现象。我负责去重点排查，有位同事用自己的手机测试后</p>
                        </div>

                    </div>
                </div>
            </div>
        </section>
        <section class="note-section">
            <div class="title">
                <h2>近期日记</h2>
                <p>记录生活的点点滴滴，回忆往事</p>
            </div>
            <div class="container note-container">
                <div class="pointer"></div>

                <div class="item" @click="router.push('/essay-detail')">
                    <div class="times">
                        <h4>2023</h4>
                        <h2>03.27</h2>
                    </div>
                    <div class="content">
                        <h3>智能图形项目进度汇报 / 寒暄</h3>
                        <p>
                            今天给公司整的智能图形项目又继续适配了一些模板，两个主题风格，似乎快有点生产可用的模样了。这里提供一个小的
                            Demo
                            截图，后续还会持续完善，功能正式上线时也会第一时间发出来给各位体验
                        </p>
                    </div>
                </div>
                <div class="item" @click="router.push('/essay-detail')">
                    <div class="times">
                        <h4>2023</h4>
                        <h2>03.27</h2>
                    </div>
                    <div class="content">
                        <h3>智能图形项目进度汇报 / 寒暄</h3>
                        <p>
                            今天给公司整的智能图形项目又继续适配了一些模板，两个主题风格，似乎快有点生产可用的模样了。这里提供一个小的
                            Demo
                            截图，后续还会持续完善，功能正式上线时也会第一时间发出来给各位体验
                        </p>
                    </div>
                </div>
                <div class="item" @click="router.push('/essay-detail')">
                    <div class="times">
                        <h4>2023</h4>
                        <h2>03.27</h2>
                    </div>
                    <div class="content">
                        <h3>智能图形项目进度汇报 / 寒暄</h3>
                        <p>
                            今天给公司整的智能图形项目又继续适配了一些模板，两个主题风格，似乎快有点生产可用的模样了。这里提供一个小的
                            Demo
                            截图，后续还会持续完善，功能正式上线时也会第一时间发出来给各位体验
                        </p>
                    </div>
                </div>
                <div class="item" @click="router.push('/essay-detail')">
                    <div class="times">
                        <h4>2023</h4>
                        <h2>03.27</h2>
                    </div>
                    <div class="content">
                        <h3>智能图形项目进度汇报 / 寒暄</h3>
                        <p>
                            今天给公司整的智能图形项目又继续适配了一些模板，两个主题风格，似乎快有点生产可用的模样了。这里提供一个小的
                            Demo
                            截图，后续还会持续完善，功能正式上线时也会第一时间发出来给各位体验
                        </p>
                    </div>
                </div>
            </div>
        </section>
        <section class="imgae-section">
            <div class="title">
                <h2>近期捕获</h2>
                <p>捕捉人生中的每一份精彩时刻与温暖</p>
            </div>
            <div class="container">
                <div class="column">
                    <div class="content">
                        <img @click="handleViewerImg" src="https://picsum.photos/200/400" alt="" />
                        <img @click="handleViewerImg" src="https://picsum.photos/200/400" alt="" />
                    </div>
                </div>
                <div class="column">
                    <div class="content">
                        <img @click="handleViewerImg" src="https://picsum.photos/200/200" alt="" />
                        <img @click="handleViewerImg" src="https://picsum.photos/200/300" alt="" />
                    </div>
                </div>
                <div class="column">
                    <div class="content">
                        <img @click="handleViewerImg" src="https://picsum.photos/200/200" alt="" />
                        <img @click="handleViewerImg" src="https://picsum.photos/200/100" alt="" />
                    </div>
                </div>
                <div class="column">
                    <div class="content">
                        <img @click="handleViewerImg" src="https://picsum.photos/200/300" alt="" />
                        <img @click="handleViewerImg" src="https://picsum.photos/200/300" alt="" />
                    </div>
                </div>
                <div class="column">
                    <div class="content">
                        <img @click="handleViewerImg" src="https://picsum.photos/200/200" alt="" />
                        <img @click="handleViewerImg" src="https://picsum.photos/200/200" alt="" />
                    </div>
                </div>
                <div class="column">
                    <div class="content">
                        <img @click="handleViewerImg" src="https://picsum.photos/200/300" alt="" />
                        <img @click="handleViewerImg" src="https://picsum.photos/200/400" alt="" />
                    </div>
                </div>
            </div>
            <button class="more">更多</button>
        </section>
        <section class="direction-section">
            <div class="title">
                <h2>风向标</h2>
                <p>看看我们去哪吧</p>
            </div>
            <div class="container">
                <span>相册</span>
                <span>时间轴</span>
                <span>我的朋友们</span>
                <span>赞赏</span>
                <span>关于我</span>
            </div>
        </section>

        <div class="mask">
            <img id="overImg" src="#" alt="" @click="handleCloseMask">
            <img class="close" src="@/assets/svg/close.svg" @click="handleCloseMask" alt="">
        </div>
    </div>
</template>
<script setup>
import { throttle } from 'lodash';

const router = useRouter()
//移动边框
const moverBorder = () => {
    nextTick(() => {
        const items = document.querySelectorAll(".note-container .item");
        const pointer = document.querySelector(".pointer");

        for (const item of items) {
            item.onmouseenter = () => {
                pointer.style.setProperty("--x", item.offsetLeft + "px");
                pointer.style.setProperty("--y", item.offsetTop + "px");
                pointer.style.setProperty("--w", item.offsetWidth + "px");
                pointer.style.setProperty("--h", item.offsetHeight + "px");
            };
        }
    });
};

//移动卡片
const moveCard = () => {
    const card = document.querySelector(".top-section .card");

    const rotationRange = [-15, 15]; // 旋转角度范围

    // 获取旋转角度的辅助函数
    function getRotation(range, mousePos, length) {
        return ((range[1] - range[0]) / length) * mousePos + range[0];
    }

    // 使用 _.throttle 节流鼠标移动事件
    const throttledMouseMove = throttle((e) => {
        const rect = card.getBoundingClientRect(); // 缓存卡片的边界信息
        const offsetX = e.clientX - rect.left; // 鼠标相对卡片的 X 偏移
        const offsetY = e.clientY - rect.top; // 鼠标相对卡片的 Y 偏移

        const rx = getRotation(rotationRange, offsetY, rect.height); // 计算 X 轴旋转角度
        const ry = -getRotation(rotationRange, offsetX, rect.width); // 计算 Y 轴旋转角度

        card.style.setProperty("--rx", `${rx}deg`);
        card.style.setProperty("--ry", `${ry}deg`);
    }, 16); // 节流时间为 16ms，大约为 60fps 的间隔

    // 鼠标移动事件
    card.onmousemove = throttledMouseMove;

    // 鼠标移出事件
    card.onmouseleave = () => {
        card.style.setProperty("--rx", "0deg");
        card.style.setProperty("--ry", "0deg");
    };
};

const handleViewerImg = (e) => {
    const target = e.target;

    const overImg = document.querySelector('#overImg')
    const mask = document.querySelector('.mask')
    // 禁止页面滚动
    document.body.style.overflow = 'hidden';

    // 显示遮罩层
    mask.style.display = 'block';

    // 设置图片源
    if (target) {
        overImg.setAttribute('src', target.src);
    }

}

const handleCloseMask = () => {
    const mask = document.querySelector('.mask')
    document.body.style.overflow = 'auto';
    mask.style.display = 'none';
    const overImg = document.querySelector('#overImg')
    overImg.removeAttribute('src')
}
onMounted(() => {
    moverBorder();
    moveCard();
});
</script>

<style lang="less" scoped>
.home-page{
    padding-bottom: 140px;
    box-sizing: border-box;
    background: #eafafb;
}
.top-section {
    height: 100vh;
    background: @primary url() top left / 11em fixed;
    display: flex;
    align-items: center;
    justify-content: center;

    .card {
        width: 800px;
        height: 400px;
        border-radius: 14px;
        background: @white-alpha-2;
        background: #ffffff79;
        backdrop-filter: blur(20px);
        --rx: 0deg;
        --ry: 0deg;
        transition: transform 0.3s, box-shadow 0.3s;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 60px;
        box-sizing: border-box;

        .card-item {
            display: flex;
            gap: 20px;
            width: 100%;
            height: 100%;

            &__content {
                flex: 1;
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                gap: 20px;
                align-items: center;
                justify-content: space-between;

                >div {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    gap: 15px;
                }
            }

            &__img {
                overflow: hidden;
                display: flex;
                align-items: center;

                img {
                    width: 200px;
                    height: 250px;
                    border-radius: 12px;
                }
            }
        }
    }

    .card:hover {
        transform: perspective(500px) rotateX(var(--rx)) rotateY(var(--ry));
    }

    .arrow {
        position: absolute;
        bottom: 30px;
        left: 50%;
        transform: translate(-50%, 0px);
        animation: arrowAni 1s ease-in-out forwards infinite;


        img {
            width: 60px;
            height: 60px;
        }
    }

    @keyframes arrowAni {
        0% {
            transform: translate(-50%, 0px);
        }

        50% {
            transform: translate(-50%, 30px);
        }

        100% {
            transform: translate(-50%, 0px);
        }
    }
}

.posts-section {
    display: flex;
    flex-direction: column;
    max-width: 1140px;
    margin: 0 auto;
    margin-top: 60px;

    .title {
        width: fit-content;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;
        background-image: url('@/assets/svg/title-code.svg');
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
        margin: 0 auto;


        h2 {
            color: #28b9be;
        }

        p {
            color: #0d3d3f;
        }
    }

    .container {
        display: flex;
        justify-content: center;
        gap: 20px;

        .content {
            flex: 1;
            margin-top: 60px;
            height: 470px;
            border-radius: 10px;
            cursor: pointer;

        }

        .content.left {
            background: #ffff;
            transform: translateY(0);
            transition: transform .5s;
            overflow: hidden;

            .detail {

                display: flex;
                flex-direction: column;
                gap: 10px;
                padding: 20px;
                box-sizing: border-box;
                color: #0d3d3f;
                position: relative;
                height: 50%;



                h3 {
                    color: #28b9be;
                    text-align: center;

                }

                &::before {
                    background: linear-gradient(transparent, #fff);
                    bottom: 0;
                    content: "";
                    display: block;
                    left: 0;
                    position: absolute;
                    right: 0;
                    height: 100%;
                    top: -100%;
                }

            }

            img {
                width: 100%;
                height: 50%;

                object-fit: cover;


            }

            &:hover {
                transform: translateY(-10px);
            }
        }

        .content.right {
            display: flex;
            flex-direction: column;
            gap: 10px;

            .item {
                width: 100%;
                height: 150px;
                transform: translateX(0);
                transition: transform .5s;
                background: #fff;
                display: flex;
                gap: 20px;
                overflow: hidden;
                border-radius: 10px;


                &:hover {
                    transform: translateX(10px);
                }

                .item-img {
                    height: 150%;
                    width: 30%;
                    transform: rotate(30deg) translateY(-16%) translateX(-30%);
                    transform-origin: center;
                    float: left;

                    img {
                        width: 100%;
                        height: 100%;
                        border-radius: 10px;
                        object-fit: cover;
                    }
                }

                .item-content {
                    flex: 1;
                    padding-top: 20px;
                    padding-right: 20px;
                    box-sizing: border-box;
                    gap: 10px;

                    h3 {
                        color: #28b9be;
                    }

                    p {
                        color: #0d3d3f;
                        padding-top: 10px;
                        box-sizing: border-box;
                    }
                }

            }
        }
    }
}

.note-section {
    display: flex;
    flex-direction: column;
    max-width: 1140px;
    margin: 0 auto;
    margin-top: 60px;

    .title {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;
        background-image: url('@/assets/svg/nav-note.svg');
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
        margin: 0 auto;

        h2 {
            color: #28b9be;
        }

        p {
            color: #0d3d3f;
        }
    }

    .container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        margin-top: 60px;

        position: relative;

        .pointer {
            position: absolute;

            --l: 30px;
            --g: 15px;
            --t: 3px;
            --w: 555px;
            --h: 200px;
            --x: 0px;
            --y: 0px;
            width: calc(var(--w) + var(--g) * 2);
            height: calc(var(--h) + var(--g) * 2);
            border: var(--t) solid #28b9be;
            left: calc(var(--x) - var(--g));
            top: calc(var(--y) - var(--g));
            transition: 0.5s;
            --mask: conic-gradient(at var(--l) var(--l), transparent 75%, red 75%) 0 0 / calc(100% - var(--l)) calc(100% - var(--l));
            mask: var(--mask);
            -webkit-mask: var(--mask);
        }

        .item {
            height: 200px;
            display: flex;
            gap: 10px;
            backdrop-filter: blur(10px);
            background: #ffffffb0;
            padding: 20px;
            box-sizing: border-box;
            border-radius: 10px;
            cursor: pointer;

            .times {
                width: 100px;
                display: flex;
                flex-direction: column;
                gap: 10px;

                h4 {
                    color: #28b9be;
                    font-weight: 400;
                }

                h2 {
                    color: #28b9be;
                }
            }

            .content {
                flex: 1;
                display: flex;
                flex-direction: column;
                gap: 10px;

                h3 {
                    color: #28b9be;
                }

                p {
                    color: #0d3d3f;
                }
            }
        }
    }
}

.imgae-section {
    display: flex;
    flex-direction: column;
    max-width: 1140px;
    margin: 0 auto;
    margin-top: 60px;

    .title {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;
        background-image: url('@/assets/svg/nav-photo.svg');
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
        margin: 0 auto;

        h2 {
            color: #28b9be;
        }

        p {
            color: #0d3d3f;
        }
    }

    .container {
        width: 100%;
        margin: 2em auto;
        display: flex;
        gap: 20px;
        justify-content: space-between;

        .column {

            flex: 1 1 0;
            display: flex;
            align-items: center;

            img {
                width: 100%;
                border-radius: 12px;
                cursor: zoom-in;
                object-fit: cover;
            }

            .content {
                display: flex;
                flex-direction: column;
                gap: 20px;

            }
        }
    }


}

.direction-section {
    display: flex;
    flex-direction: column;
    max-width: 1140px;
    margin: 0 auto;
    margin-top: 60px;

    .title {
        width: fit-content;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;
        background-image: url('@/assets/svg/title-arrow.svg');
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
        margin: 0 auto;


        h2 {
            color: #28b9be;
        }

        p {
            color: #0d3d3f;
        }
    }

    .container {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 30px;
        margin-top: 60px;

        span {
            color: #0d3d3f;
            position: relative;
            display: inline-block;
            cursor: pointer;

            &::after {
                content: '';
                width: 0%;
                height: 3px;
                border-radius: 20px;
                background: #fc2d2d;
                bottom: -5px;
                left: 50%;
                transform: translateX(-50%);
                position: absolute;
                transition: width 0.5s;
            }

            &:hover::after {
                width: 100%;
            }
        }
    }
}

.more {
    border-radius: 20px;
    width: 120px;
    height: 40px;
    line-height: 40px;
    outline: none;
    margin: 0 auto;
    border: none;
    background: #28b9be;
    font-weight: 500;
    position: relative;
    overflow: hidden;
    z-index: 1;
    cursor: pointer;
    transition: background 0.8s;

    &::before {
        content: '';
        width: 0;
        height: 40px;
        left: 0;
        top: 0;
        position: absolute;
        border-radius: 20px;
        transition: width 0.2s ease-in-out;
        z-index: -1;

    }

    &:hover {
        color: #fff;
        background: transparent;

        &::before {
            background: #fc2d2d;
            width: 120px;
        }

    }
}

.mask {
    position: fixed;
    width: 100%;
    height: 100%;
    inset: 0;
    z-index: 100000;
    background: #000000a9;
    display: none;

    #overImg {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .close {
        position: absolute;
        top: 20px;
        right: 20px;
        width: 30px;
        height: 30px;
        cursor: pointer;
    }
}
</style>
